package ikar.nrd.fillingref.generator;

import ikar.nrd.model.FillingRef;
import ikar.nrd.model.PlateCodes;
import ikar.nrd.model.XsltNodeType;

import javax.swing.tree.DefaultMutableTreeNode;

public class CommonFIeldsGenerator {

	public static DefaultMutableTreeNode getTradeElement() {
		FillingRef trade = new FillingRef("", PlateCodes.TRADE, "trade", false);
		trade.setFullPath("trade");
		DefaultMutableTreeNode tradeNode = new DefaultMutableTreeNode(trade);
		DefaultMutableTreeNode tradeHeader = new DefaultMutableTreeNode(new FillingRef("", PlateCodes.TRADE_HEADER, "tradeHeader", false));
		tradeNode.add(tradeHeader);

		DefaultMutableTreeNode paertyTradeIdentifier = new DefaultMutableTreeNode(new FillingRef("", PlateCodes.TABLE_PARTYTRADEIDENTIFIER, "partyTradeIdentifier", XsltNodeType.FOREACH));
		tradeHeader.add(paertyTradeIdentifier);
		
		FillingRef partyTradeIdentTradeId = new FillingRef("Номер, присвоенный участником", PlateCodes.PARTYTRADEIDENTIFIER_TRADEID, "tradeId", false);
		partyTradeIdentTradeId.setFullPath("trade/tradeHeader/tradeId");
		paertyTradeIdentifier.add(new DefaultMutableTreeNode(partyTradeIdentTradeId));
		
		DefaultMutableTreeNode paertyReference = new DefaultMutableTreeNode(new FillingRef("", "TRADE_PARTYIDENTIFIER_PARTYREFFERENCE", "partyReference", false));
		FillingRef partyRef = new FillingRef("Ссылка на участника", PlateCodes.PARTYTRADEIDENTIFIER_PARTYREFERENCE, "@href", false);
		partyRef.setAttribute(true);
		partyRef.setFullPath("trade/tradeHeader/partyTradeIdentifier/partyReference/@href");
		paertyReference.add(new DefaultMutableTreeNode(partyRef));
		paertyTradeIdentifier.add(paertyReference);

		FillingRef partyLinkId = new FillingRef("Номер генерального соглашения в системе участника", PlateCodes.PARTYTRADEIDENTIFIER_LINKEDID_R, "linkId linkIdScheme=\"http://repository.nsd.ru/coding-scheme/linkid(nsdrus)\"", true);
		partyLinkId.setFullPath("trade/tradeHeader/partyTradeIdentifier/linkId linkIdScheme=\"http://repository.nsd.ru/coding-scheme/linkid(nsdrus)");
		paertyTradeIdentifier.add(new DefaultMutableTreeNode(partyLinkId));

		DefaultMutableTreeNode paertyTradeInformation = new DefaultMutableTreeNode(new FillingRef("", PlateCodes.TABLE_PARTYTRADEINFORMATION, "partyTradeInformation", false));
		tradeHeader.add(paertyTradeInformation);

		DefaultMutableTreeNode tradeInformationPartyReference = new DefaultMutableTreeNode(new FillingRef("", "TRADE_PARTYIDENTIFIER_PARTYREFFERENCE", "partyReference", false));
		FillingRef tradeInformationPartyReferenceHref = new FillingRef("", PlateCodes.PARTYTRADEIDENTIFIER_PARTYREFERENCE, "@href", false);
		tradeInformationPartyReferenceHref.setAttribute(true);
		tradeInformationPartyReferenceHref.setFullPath("trade/tradeHeader/partyTradeInformation/partyReference/@href");
		tradeInformationPartyReference.add(new DefaultMutableTreeNode(tradeInformationPartyReferenceHref));

		paertyTradeInformation.add(tradeInformationPartyReference);

		FillingRef tradeDate = new FillingRef("Дата заключения сделки", PlateCodes.TRADEHEADER_TRADEDATE, "tradeDate", false);
		tradeDate.setFullPath("trade/tradeHeader/partyTradeInformation/tradeDate");
		paertyTradeInformation.add(new DefaultMutableTreeNode(tradeDate));

		FillingRef clearedDate = new FillingRef("", PlateCodes.TRADEHEADER_CLEAREDDATE, "clearedDate", false);
		clearedDate.setFullPath("trade/tradeHeader/partyTradeInformation/clearedDate");
		paertyTradeInformation.add(new DefaultMutableTreeNode(clearedDate));
		return tradeNode;
	}


}

